#ifndef __LOG_H
#define __LOG_H

#include "W25Q32.h"
#define BLOCK_HEADER 0xA55A
#define LOG_MAGIC_NUNMBER 0x6B7FE19C
#define SECTOR_SIZE 4*1024 //4KB
#define SECTOR_CNT  1024
#define PAGE_SIZE  255     //256Bytes


typedef enum
{
    LOG_DATA_TYPE_STATUS = 0x01,
}log_data_type_t;

typedef __packed struct 
{
    uint32_t magic_number;
    uint16_t log_sn;
}log_header_t;

typedef __packed struct 
{
    uint16_t block_header;
    uint8_t data_type;
    uint8_t data_length;
}data_block_header_t;

typedef __packed struct
{
    float motor_speed;
    float servo1_angle;
    float servo2_angle;
    float servo3_angle;
    float servo4_angle;
    float voltage;
    float gyrox;
    float gyroy;
    float gyroz;
    float accelx;
    float accely;
    float accelz;
    float roll;
    float pitch;
    float yaw;
    float positionx;
    float positiony;
    float positionz;
    float speedx;
    float speedy;
    float speedz;
}status_log_pack_t;
//__packed
typedef __packed struct 
{
    data_block_header_t header;
    status_log_pack_t pack;
    uint32_t crc32;
}status_log_t;


uint8_t log_init(void);
void status_log_inqueue(void *pack);
void log_task(void);
#endif

